package com.xueyi.aixihu.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.xueyi.aixihu.annotation.Aes;
import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.entity.vo.CascaderDataVo;
import com.xueyi.aixihu.entity.vo.DtNewsSortTreeVo;
import com.xueyi.aixihu.entity.vo.SelectVo;
import com.xueyi.aixihu.exception.SzException;
import com.xueyi.aixihu.reqeust.FindClassifyListByPidReq;
import com.xueyi.aixihu.reqeust.FindClassifyReq;
import com.xueyi.aixihu.response.DtNewsSortListResponse;
import com.xueyi.aixihu.response.FindThreeClassifyByIdResponse;
import com.xueyi.aixihu.response.TwoClassifyResponse;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.DtNewsSortService;
import com.xueyi.aixihu.status.SystemCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @authoer:hxs
 * @createDate:2022/8/16
 * @description: 文章、社区分裂操作接口
 */
@RestController
public class DtNewsSortController extends BaseController {
    @Autowired
    private DtNewsSortService dtNewsSortService;

    /**
     * 页面初始化时查询分类
     *
     * @return
     */
    //    @Aes
    @RequestMapping("/dtClassify/findAllClassify")
    public BaseResponse<DtNewsSortListResponse> findAllClassify() {
        DtNewsSortListResponse response = dtNewsSortService.findAllClassify();
        return BaseResponse.success(response);
    }

    /**
     * 通过一级分类id查询二级分类以及三级分类
     *
     * @param findClassifyReq
     * @return
     */
//    @Aes
    @RequestMapping("/dtClassify/findTwoClassifyById")
    public BaseResponse<TwoClassifyResponse> findTwoClassifyById(@Validated FindClassifyReq findClassifyReq) throws SzException {
        TwoClassifyResponse twoClassifyResponse = dtNewsSortService.findTwoClassifyById(findClassifyReq);
        return BaseResponse.success(twoClassifyResponse);
    }

    /**
     * 通过二级查三级
     */
    @RequestMapping("/dtClassify/findFourClassifyById")
    public BaseResponse<FindThreeClassifyByIdResponse> findFourClassifyById(@Validated FindClassifyListByPidReq findClassifyReq) throws SzException {
        FindThreeClassifyByIdResponse response = dtNewsSortService.findFourClassifyById(findClassifyReq);
        return BaseResponse.success(response);
    }

    /**
     * 通过三级级分类id查询四级分类
     *
     * @param findClassifyReq
     * @return
     */
//    @Aes
    @RequestMapping("/dtClassify/findThreeClassifyById")
    public BaseResponse<List<SelectVo>> findThreeClassifyById(@Validated FindClassifyListByPidReq findClassifyReq) throws SzException {
        List<SelectVo> threeMenu = dtNewsSortService.findThreeClassifyById(findClassifyReq);
        return BaseResponse.success(threeMenu);
    }


    /**
     * 获取联级菜单数据
     *
     * @return
     */
//    @Aes
    @RequestMapping("/dtClassify/findCascaderData")
    public BaseResponse<List<CascaderDataVo>> findCascaderData() {
        List<CascaderDataVo> list = dtNewsSortService.findCascaderData();
        return BaseResponse.success(list);
    }

    /**
     * 查询出树级结果的菜单
     *
     * @return
     */
    @RequestMapping("/dtClassify/findTree")
    public BaseResponse<List<DtNewsSortTreeVo>> findTree() {
        return BaseResponse.build(SystemCode.SUCCESS, "查询成功", dtNewsSortService.findTree());
    }

    /**
     * 删除类型管理树的结点
     *
     * @param id
     */
    @RequestMapping("/dtClassify/deleteTreeNode")
    public BaseResponse<Boolean> deleteTreeNode(Integer id) {
        return dtNewsSortService.deleteTreeNode(id);
    }

    /**
     * 增加类型管理树的结点
     *
     * @param pid
     * @param name
     */
    @RequestMapping("/dtClassify/addTreeNode")
    public BaseResponse<Boolean> addTreeNode(Integer pid, String name) {
        return dtNewsSortService.addTreeNode(pid, name);
    }

}
